
******************************* The program decomposes the share of new product according to the Rauch definition
******************************* Do not forget to ghange the starting and ending year of loop depending on 
******************************* def of New product
******************************* In the files the results show as New and VNew, that is because the program was not corrected completely
******************************* these labels do refer to trad product as specify by the status and the databases names.

clear
set memory 700m
use export.dta, clear
save export2.dta, replace
sort product
save, replace

merge product using Rauch.dta
drop if _merge == 1
drop if _merge == 2
drop _merge 
save, replace


foreach i of numlist 1989/2005{
*foreach i of numlist 1990/2004{


rename Exportvalue`i' Exportvalue

** STATUS


**************new product 2 periods


*local j1 = `i' - 1
*local j2 = `i' - 2
*gen Pre= (Exportvalue`j1'+ Exportvalue`j2')

*local k1 =`i' + 1
*local k2 =`i' + 2
*gen Post= (Exportvalue`k1'+ Exportvalue`k2')


*gen Status=1
*replace Status=2 if Pre==0 &  Exportvalue~=0 & Exportvalue`k1'~=0 & Exportvalue`k2'~=0 
*replace Status=3 if Pre~=0
*replace Status=3 if Pre==0 &  Exportvalue~=0 & Post~=0 & Status ~= 2
*label var Status "1=non exported / 2=new exports / 3=trad exports"
*drop Pre Post




**************new product 1 period

local j = `i' - 1
gen Pre= Exportvalue`j'
local k =`i' + 1
gen Post= Exportvalue`k'

gen Status=1
replace Status=2 if Pre==0 &  Exportvalue~=0 & Post~=0 
replace Status=3 if Pre~=0
label var Status "1=non exported / 2=new exports / 3=trad exports"
drop Pre Post


********************


rename  Exportvalue ExportvalueA
replace ExportvalueA = 0 if Status==1

ren ExportvalueA Exportvalue`i'
ren Status Status`i'



** NUMBER OF NEW LINES


gen S=0
replace S=1 if  Status`i'==3
egen Newrcons`i'=sum( S), by( reporter rconser)
egen Newrlib`i'=sum( S), by( reporter rliberal)
drop S
gen S=0
replace S=Exportvalue`i' if  Status`i'==3
egen VNewrcons`i'=sum(S), by( reporter rconser)
egen VNewrlib`i'=sum(S), by( reporter rliberal)
drop S
compress


}

save Trad_period_rauch.dta, replace

****************************************compute share for Rauch conservative measure
clear
use Trad_period_rauch.dta, clear

keep reporter rconser Newrcons1989 VNewrcons1989 Newrcons1990 VNewrcons1990 Newrcons1991 VNewrcons1991 Newrcons1992 VNewrcons1992 Newrcons1993 VNewrcons1993 Newrcons1994 VNewrcons1994 Newrcons1995 VNewrcons1995 Newrcons1996 VNewrcons1996 Newrcons1997 VNewrcons1997 Newrcons1998 VNewrcons1998 Newrcons1999 VNewrcons1999 Newrcons2000 VNewrcons2000 Newrcons2001 VNewrcons2001 Newrcons2002 VNewrcons2002 Newrcons2003 VNewrcons2003 Newrcons2004 VNewrcons2004 Newrcons2005 VNewrcons2005 
save Trad_period_rauchcons.dta, replace
collapse Newrcons1989 VNewrcons1989 Newrcons1990 VNewrcons1990 Newrcons1991 VNewrcons1991 Newrcons1992 VNewrcons1992 Newrcons1993 VNewrcons1993 Newrcons1994 VNewrcons1994 Newrcons1995 VNewrcons1995 Newrcons1996 VNewrcons1996 Newrcons1997 VNewrcons1997 Newrcons1998 VNewrcons1998 Newrcons1999 VNewrcons1999 Newrcons2000 VNewrcons2000 Newrcons2001 VNewrcons2001 Newrcons2002 VNewrcons2002 Newrcons2003 VNewrcons2003 Newrcons2004 VNewrcons2004 Newrcons2005 VNewrcons2005  , by(reporter rconser)
reshape long Newrcons VNewrcons, i(reporter rconser) j(year)
save Trad_period_rauchcons.dta, replace

*keep reporter rconser  Newrcons1990 VNewrcons1990 Newrcons1991 VNewrcons1991 Newrcons1992 VNewrcons1992 Newrcons1993 VNewrcons1993 Newrcons1994 VNewrcons1994 Newrcons1995 VNewrcons1995 Newrcons1996 VNewrcons1996 Newrcons1997 VNewrcons1997 Newrcons1998 VNewrcons1998 Newrcons1999 VNewrcons1999 Newrcons2000 VNewrcons2000 Newrcons2001 VNewrcons2001 Newrcons2002 VNewrcons2002 Newrcons2003 VNewrcons2003 Newrcons2004 VNewrcons2004
*save Trad_period_rauchcons.dta, replace
*collapse  Newrcons1990 VNewrcons1990 Newrcons1991 VNewrcons1991 Newrcons1992 VNewrcons1992 Newrcons1993 VNewrcons1993 Newrcons1994 VNewrcons1994 Newrcons1995 VNewrcons1995 Newrcons1996 VNewrcons1996 Newrcons1997 VNewrcons1997 Newrcons1998 VNewrcons1998 Newrcons1999 VNewrcons1999 Newrcons2000 VNewrcons2000 Newrcons2001 VNewrcons2001 Newrcons2002 VNewrcons2002 Newrcons2003 VNewrcons2003 Newrcons2004 VNewrcons2004  , by(reporter rconser)
*reshape long Newrcons VNewrcons, i(reporter rconser) j(year)
*save Trad_period_rauchcons.dta, replace

replace Newrcons = . if VNewrcons == 0

egen totNew = sum(Newrcons), by (reporter year)
gen shareNew = (Newrcons/totNew)*100
egen n = count(year) if rconser == "n" & VNewrcons~=0
egen sumshare = sum(shareNew) if rconser == "n"
gen sharen = sumshare/n
egen r = count(year) if rconser == "r" & VNewrcons~=0
egen sumsharer = sum(shareNew) if rconser == "r"
gen sharer = sumsharer/r
egen w = count(year) if rconser == "w" & VNewrcons~=0
egen sumsharew = sum(shareNew) if rconser == "w"
gen sharew = sumsharew/w


egen totVNew = sum(VNewrcons), by (reporter year)
gen shareVNew = (VNewrcons/totVNew)*100
egen sumVshare = sum(shareVNew) if rconser == "n" 
gen Vsharen = sumVshare/n
egen sumVsharer = sum(shareVNew) if rconser == "r" 
gen Vsharer = sumVsharer/r
egen sumVsharew = sum(shareVNew) if rconser == "w" 
gen Vsharew = sumVsharew/w

drop reporter year Newrcons VNewrcons totNew shareNew n n sumshare r sumsharer w sumsharew totVNew shareVNew sumVshare sumVsharer sumVsharew
collapse  sharen sharer sharew Vsharen Vsharer Vsharew, by  (rconser)

save Trad_period_rauchcons.dta, replace

****************************************compute share for Rauch liberal measure

use Trad_period_rauch.dta, clear

keep reporter rliberal Newrlib1989 VNewrlib1989 Newrlib1990 VNewrlib1990 Newrlib1991 VNewrlib1991 Newrlib1992 VNewrlib1992 Newrlib1993 VNewrlib1993 Newrlib1994 VNewrlib1994 Newrlib1995 VNewrlib1995 Newrlib1996 VNewrlib1996 Newrlib1997 VNewrlib1997 Newrlib1998 VNewrlib1998 Newrlib1999 VNewrlib1999 Newrlib2000 VNewrlib2000 Newrlib2001 VNewrlib2001 Newrlib2002 VNewrlib2002 Newrlib2003 VNewrlib2003 Newrlib2004 VNewrlib2004 Newrlib2005 VNewrlib2005 
save Trad_period_rauchlib.dta, replace
collapse Newrlib1989 VNewrlib1989 Newrlib1990 VNewrlib1990 Newrlib1991 VNewrlib1991 Newrlib1992 VNewrlib1992 Newrlib1993 VNewrlib1993 Newrlib1994 VNewrlib1994 Newrlib1995 VNewrlib1995 Newrlib1996 VNewrlib1996 Newrlib1997 VNewrlib1997 Newrlib1998 VNewrlib1998 Newrlib1999 VNewrlib1999 Newrlib2000 VNewrlib2000 Newrlib2001 VNewrlib2001 Newrlib2002 VNewrlib2002 Newrlib2003 VNewrlib2003 Newrlib2004 VNewrlib2004 Newrlib2005 VNewrlib2005   , by(reporter rliberal)
reshape long Newrlib VNewrlib, i(reporter rliberal) j(year)
save Trad_period_rauchlib.dta, replace

*keep reporter rliberal Newrlib1990 VNewrlib1990 Newrlib1991 VNewrlib1991 Newrlib1992 VNewrlib1992 Newrlib1993 VNewrlib1993 Newrlib1994 VNewrlib1994 Newrlib1995 VNewrlib1995 Newrlib1996 VNewrlib1996 Newrlib1997 VNewrlib1997 Newrlib1998 VNewrlib1998 Newrlib1999 VNewrlib1999 Newrlib2000 VNewrlib2000 Newrlib2001 VNewrlib2001 Newrlib2002 VNewrlib2002 Newrlib2003 VNewrlib2003 Newrlib2004 VNewrlib2004  
*save Trad_period_rauchlib.dta, replace
*collapse Newrlib1990 VNewrlib1990 Newrlib1991 VNewrlib1991 Newrlib1992 VNewrlib1992 Newrlib1993 VNewrlib1993 Newrlib1994 VNewrlib1994 Newrlib1995 VNewrlib1995 Newrlib1996 VNewrlib1996 Newrlib1997 VNewrlib1997 Newrlib1998 VNewrlib1998 Newrlib1999 VNewrlib1999 Newrlib2000 VNewrlib2000 Newrlib2001 VNewrlib2001 Newrlib2002 VNewrlib2002 Newrlib2003 VNewrlib2003 Newrlib2004 VNewrlib2004    , by(reporter rliberal)
*reshape long Newrlib VNewrlib, i(reporter rliberal) j(year)
*save Trad_period_rauchlib.dta, replace

replace Newrlib = . if VNewrlib == 0

egen totNew = sum(Newrlib), by (reporter year)
gen shareNew = (Newrlib/totNew)*100
egen n = count(year) if rliberal == "n" & & VNewrlib~=0
egen sumshare = sum(shareNew) if rliberal == "n"
gen sharen = sumshare/n
egen r = count(year) if rliberal == "r" & & VNewrlib~=0
egen sumsharer = sum(shareNew) if rliberal == "r"
gen sharer = sumsharer/r
egen w = count(year) if rliberal == "w" & & VNewrlib~=0
egen sumsharew = sum(shareNew) if rliberal == "w"
gen sharew = sumsharew/w


egen totVNew = sum(VNewrlib), by (reporter year)
gen shareVNew = (VNewrlib/totVNew)*100
egen sumVshare = sum(shareVNew) if rliberal == "n"
gen Vsharen = sumVshare/n
egen sumVsharer = sum(shareVNew) if rliberal == "r"
gen Vsharer = sumVsharer/r
egen sumVsharew = sum(shareVNew) if rliberal == "w"
gen Vsharew = sumVsharew/w

drop reporter year Newrlib VNewrlib totNew shareNew n n sumshare r sumsharer w sumsharew totVNew shareVNew sumVshare sumVsharer sumVsharew
collapse  sharen sharer sharew Vsharen Vsharer Vsharew, by  (rliberal)

save Trad_period_rauchlib.dta, replace
use Trad_period_rauchlib.dta

